#include <iostream>
#include <vector>
#include <chrono> 
#include <omp.h> 

int main() {
    const int n = 30000000;

    std::vector<int> a(n); 
    for (int i = 0; i < n; i++) {
        a[i] = i + 1; 
    }
    auto start = std::chrono::high_resolution_clock::now();
    long long sum1 = 0, sum2 = 0;

#pragma omp parallel for reduction(+:sum1, sum2)
    for (int i = 0; i < n; i += 2) {
        sum1 += a[i];         
        if (i + 1 < n) {      
            sum2 += a[i + 1]; 
        }
    }

    long long sum = sum1 + sum2; 
    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> elapsed = end - start;
    std::cout << "数组元素的总和为: " << sum << std::endl;
    std::cout << "计算耗时: " << elapsed.count() << " 秒" << std::endl;
    return 0;
}
